<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    Array.selfForm = function (val = new SelfSet()) {
        try {
            return Object.values(val)
        } catch {
            return []
        }
    }

    function SelfSet(arr = []) {
        const cache = arr.filter((val, index, arr) => arr.indexOf(val) === index)

        for (let i = 0; i < cache.length; i++) {
            this[i] = cache[i]
        }

        Object.defineProperty(this, 'size', {value: cache.length})
    }

    const result = new SelfSet([1, 2, 3, 4, 5, 1, 2, 3, 4, 5])
    console.log(result);
    console.log(Array.selfForm(result))

</script>
</body>
</html>
